/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.            */
/*                                                                 */
/*  NAME      = t__sqlserver_int_pow.c                             */
/*  NOTE      =                                                    */
/*  DATE      = 2014/11/24 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <CUnit/Basic.h>

#include <frcomm.h>
#include <sqlserver/config.h>

/*******************************************************************************
*  FUNC     :  解析LOGIN数据
*  ARGS     :  pp_buffer(buffer)
*           :  p_ui_buffer_len(buffer长度)
*           :  i_endian_type(网络字节序标志(0表示需要转换，1表示不需要))
*           :  p_us_size(出力实际长度)
*  RTN      :  0       (normal)
*              1       (error)
*  NOTE     :
*******************************************************************************/
extern int __sqlserver_int_pow(unsigned long long ull_x, unsigned long long ull_y, unsigned long long *p_ull_result);


static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_ret = 0;
    unsigned long long ull_x = 0;
    unsigned long long ull_y = 10;
    unsigned long long ull_result = 0;

    i_ret = __sqlserver_int_pow(ull_x, ull_y, &ull_result);
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(ull_result, 0);

    return;
}

static void __case2(void)
{
    int i_ret = 0;
    unsigned long long ull_x = 10;
    unsigned long long ull_y = 0;
    unsigned long long ull_result = 0;

    i_ret = __sqlserver_int_pow(ull_x, ull_y, &ull_result);
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(ull_result, 1);

    return;
}

static void __case3(void)
{
    int i_ret = 0;
    unsigned long long ull_x = 10;
    unsigned long long ull_y = 10;
    unsigned long long ull_result = 0;

    i_ret = __sqlserver_int_pow(ull_x, ull_y, &ull_result);
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(ull_result, 10000000000);

    return;
}

static void __case4(void)
{
    int i_ret = 0;
    unsigned long long ull_x = 10000000000;
    unsigned long long ull_y = 10;
    unsigned long long ull_result = 0;

    i_ret = __sqlserver_int_pow(ull_x, ull_y, &ull_result);
    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    return;
}

int add_suite__sqlserver_int_pow(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __sqlserver_int_pow()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
